Imports ValidationFramework
Imports ValidationFramework.Web.ASP
Imports QSBusinessLayerVB
Imports System

Partial Public Class FormViewForm
  Inherits Page
  ' Methods
  Protected Sub OnPersonSourceUpdated(ByVal sender As Object, ByVal e As ObjectDataSourceStatusEventArgs)
    If ((Not e.Exception Is Nothing) AndAlso TypeOf e.Exception.InnerException Is ArgumentException) Then
      errorsLabel.Text = e.Exception.InnerException.Message
      e.ExceptionHandled = True
    Else
      errorsLabel.Text = String.Empty
      personFormView.DataBind()
    End If
  End Sub

  Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
        Helper.AddValidation(validatorGenerator.GetValidatorGenerator(), New FindControl(AddressOf personFormView.FindControl))
  End Sub

  Protected Sub personFormView_ItemUpdating(ByVal sender As Object, ByVal e As FormViewUpdateEventArgs)
    e.Cancel = Not MyBase.IsValid
  End Sub

  Protected Sub validatorGenerator_TargetObjectRequired(ByVal sender As Object, ByVal e As TargetObjectRequiredEventArgs)
    If (editingPersonTemp Is Nothing) Then
      editingPersonTemp = Helper.GetPerson(New FindControl(AddressOf personFormView.FindControl))
    End If
    e.TargetObject = editingPersonTemp
  End Sub


  ' Fields
  Private editingPersonTemp As Person
End Class


